from SimpleXMLRPCServer import SimpleXMLRPCServer
from SimpleXMLRPCServer import SimpleXMLRPCRequestHandler
import pickle
from orion_modele import *
import time

# Creer un serveur
server = SimpleXMLRPCServer(("127.0.0.1", 8000),
                            requestHandler=SimpleXMLRPCRequestHandler)

class ControleurServeur(object):
    def __init__(self):
        self.modele=JeuOrion(self,"serveur")
        
    def nouveauJoueur(self,nom):
        self.modele.ajouteJoueur(nom)
        return pickle.dumps(self.modele.univers)
    def newAction(self,action):
        nom,style,action=action
        self.modele.updateMessage(nom,style,action)
        return 1
    def rienDeNeuf(self,nom):
        msg=self.modele.message[nom]
        if msg:
            self.modele.message[nom]=[]
            return msg
        else:
            return ["RIEN",time.time()]
    
server.register_instance(ControleurServeur())

# Demarrer la boucle du serveur
print "OK, serveur demarrer"
server.serve_forever()
print "OK, serveur arreter"









